from django.template import Library
from fblaproj.socialgraph.models import UserLink
from fblaproj.socialgraph.util import get_people_user_follows, get_people_following_user
from django.contrib.auth.models import User

register = Library()
def following(value, context):
	from_user = context.user
	try:
		to_user = UserLink.objects.filter(from_user=from_user).filter(to_user=value)
	except UserLink.DoesNotExist:
		return "Not Following"
	return get_people_user_follows(from_user)

def is_following(value, context):
	from_user = context.user
	try:
		value_user = User.objects.filter(pk=value.id)
	except User.DoesNotExist:
		return "none"
	for i in value_user:
		if (from_user == i):
			return ""
	follows = get_people_user_follows(from_user)
	
	if (value in follows):
		return "unfollow"
	else:
		return "follow"
def is_following_text(value, context):
	from_user = context.user
	try:
		value_user = User.objects.filter(pk=value.id)
	except User.DoesNotExist:
		return "none"
	for i in value_user:
		if (from_user == i):
			return ""
	follows = get_people_user_follows(from_user)
	if (value in follows):
		return "Stop Following"
	else:
		return "Follow"

register.filter(following)
register.filter(is_following)
register.filter(is_following_text)